<%-- 
    Document   : hoantat
    Created on : Jun 16, 2013, 2:56:19 AM
    Author     : URUKU
--%>

<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.Statement"%>
<%@page import="Func.Conn"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <%@ include file="head.jsp" %>

    <body>
        <div id="divContainer">
    
    <%@ include file="divHeader.jsp" %>
	
    </br>		
    <div class="clr"></div>
				
    <%@ include file="divLeft.jsp" %>
    
	<div id = "divMid">
            <div id ="pro4">
                <%
                int MaxDh = 0;
                 Connection con = Conn.GetCon();
                 
                 Statement statement = con.createStatement();
                 ResultSet resultSet = statement.executeQuery
 ("select MAX(MADH) as 'm' FROM DONHANG  ");
                 while(resultSet.next())
                 {
                    MaxDh =    resultSet.getInt("m");
                 }

                 Statement stm = con.createStatement();
                String sql = "";         
            Statement stmt = con.createStatement();
            int smt = 0;
            
                TrangSuc.Giohang gh=(TrangSuc.Giohang)(session.getAttribute("giohang"));
                
        if(gh!=null){

       
        for(int i=0;i<=gh.soMonHang()-1;i++){
        TrangSuc.Monhang mh=gh.LayMonHang(i);
       
        sql = "insert into CHITIETDONHANG (MaDH,Masp,Soluong) values('"+ MaxDh +"',' " + mh.getTen() + "','"+ mh.getSoluong() +"')";
        smt = stmt.executeUpdate(sql);
        
        }
        
        }
                if(smt >= 1)
            {                 
                %>    
<h1> Bạn Đã Mua Hàng Thành Công .</h1>
     </div>
        </div>
       <% } %>
    <%@ include file="divFooter.jsp" %>  
         </div>

    </body>
</html>
